﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.h00_jxflMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void h00_jxfl_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            h00_jxflMgr mgr = new h00_jxflMgr();
            e.Total = int.Parse(mgr.GetRecordCount_h00_jxfl(e.Parameters[h00_jxfl_Filter.ParamPrefix]));
            IList<h00_jxfl> list = mgr.FindAllByPage_h00_jxfl(e.Start.ToString(), e.Limit.ToString(), e.Parameters[h00_jxfl_Filter.ParamPrefix]);
            h00_jxfl_MainStore.DataSource = list;
            h00_jxfl_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            h00_jxflMgr mgr = new h00_jxflMgr();
            RowSelectionModel sm = h00_jxfl_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                h00_jxfl _h00_jxfl = new h00_jxfl();
                _h00_jxfl.jxflid = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_h00_jxfl(_h00_jxfl))
                {
                    log.Debug("h00_jxfl中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            h00_jxfl_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            h00_jxflMgr mgr = new h00_jxflMgr();
            h00_jxfl _h00_jxfl = new h00_jxfl();
            if (Hid.Text.Length > 0)
                _h00_jxfl = mgr.FindById_h00_jxfl(int.Parse(Hid.Text));
            
			_h00_jxfl.jxflmc = Txtjxflmc.Text.Trim();
			_h00_jxfl.szbm = Txtszbm.Text.Trim();
			_h00_jxfl.pybm = Txtpybm.Text.Trim();
			_h00_jxfl.wbbm = Txtwbbm.Text.Trim();
			_h00_jxfl.qtbm = Txtqtbm.Text.Trim();
			_h00_jxfl.xzbz = Txtxzbz.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_h00_jxfl(_h00_jxfl);
            else
                isok = mgr.Add_h00_jxfl(_h00_jxfl);
            if (isok)
            {
                h00_jxfl_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("h00_jxfl中执行了保存（插入或修改），并成功");
                h00_jxfl_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}